/*
 * Copyright (c) 2021.版权所有高金磊
 */

package 领扣算法.A简单题.独特的电子邮件地址;

import java.util.HashSet;

public class Main {
    public static void main(String arg[]) {//main--来自高金磊

//        new Main().numUniqueEmails(new String[]{"a@leetcode.com","b@leetcode.com","c@leetcode.com"});
        new Main().numUniqueEmails(new String[]{"test.email+alex@leetcode.com", "test.e.mail+bob.cathy@leetcode.com", "testemail+david@lee.tcode.com"});
    }

    public int numUniqueEmails(String[] emails) {
        HashSet<String> res = new HashSet<>();
        for (int i = 0; i < emails.length; i++) {
            String plus = plus(emails[i]);
            res.add(plus);
            System.out.println(plus);

        }
        return res.size();
    }

    private String plus(String s) {
        String[] middle = s.split("@");
        return (middle[0].split("[+]")[0]).replaceAll("[.]", "") + "@" + middle[1];
    }
}
